package main

import (
	"fmt"
	"github.com/pkg/errors"
	"golang.org/x/net/context"
	"golang.org/x/sync/errgroup"
	"net/http"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	g, ctx := errgroup.WithContext(context.Background())

	s := &http.Server{}

	g.Go(func() error {
		return s.ListenAndServe()
	})

	g.Go(func() error {
		quit := make(chan os.Signal, 0)
		signal.Notify(quit, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)

		select {
		case <-ctx.Done():
			return ctx.Err()
		case sig := <-quit:
			return errors.New(fmt.Sprintf("get os signal: %v", sig))
		}
	})

	g.Wait()
}
